package com.example.bookkeeping_book.utility;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class MySqlite extends SQLiteOpenHelper {
    public MySqlite(Context context) {
        super(context, "account.db", null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        String createSql = "CREATE TABLE account(id INTEGER primary key AUTOINCREMENT,consumerId INTEGER,consumption_item VARCHER(20),amount DOUBLE, date VARCHER(20), remarks VARCHER(255))";
        sqLiteDatabase.execSQL(createSql);
        createSql = "CREATE TABLE consumer(id INTEGER primary key AUTOINCREMENT,name VARCHER(20))";
        sqLiteDatabase.execSQL(createSql);
        createSql = "CREATE TABLE budget(id INTEGER,budget DOUBLE)";
        sqLiteDatabase.execSQL(createSql);
        createSql = "CREATE TABLE user(user  VARCHER(20),pass VARCHER(10))";
        sqLiteDatabase.execSQL(createSql);
        ContentValues values = new ContentValues();
        values.put("name", "我的");
        sqLiteDatabase.insert("consumer", null, values);
        values.clear();
        values.put("id", 0);
        values.put("budget", 0);
        sqLiteDatabase.insert("budget", null, values);
        values.clear();

        values.put("user", "admin");
        values.put("pass", "123456");
        sqLiteDatabase.insert("user", null, values);
        values.clear();
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {

    }
}
